package com.hyt.it.ogt.kq.service.bm.service.impl;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.hyt.core.base.BaseServiceImpl;
import com.hyt.it.ogt.kq.service.bm.mapper.ProjectDataDownLoadRecordMapper;
import com.hyt.it.ogt.kq.service.bm.model.entity.ProjectDataDownLoadRecord;
import com.hyt.it.ogt.kq.service.bm.service.IProjectDataDownLoadRecordService;

/**
 */
@Service
public class ProjectDataDownLoadRecordServiceImpl extends BaseServiceImpl<ProjectDataDownLoadRecordMapper, ProjectDataDownLoadRecord> implements IProjectDataDownLoadRecordService {

	@Resource
	private ProjectDataDownLoadRecordMapper projectDataDownLoadRecordMapper;

	@Override
	public ProjectDataDownLoadRecord getProjectDataDownLoadRecord(String projectId, String officeId, String dlParam, String permissions, String fileType) throws Exception {
		return projectDataDownLoadRecordMapper.getLastOneByProjectAndFileType(projectId, officeId, dlParam, permissions, fileType);
	}

	@Override
	public Integer getProjectDataDownLoadRecordTimes(String projectId, String officeId, String dlParam, String permissions, String fileType) throws Exception {
		return projectDataDownLoadRecordMapper.getLastOneByProjectAndFileTypeTimes(projectId, officeId, dlParam, permissions, fileType);
	}

	@Override
	public List<ProjectDataDownLoadRecord> getIsRunningDownloadZip(Set<String> projectIds, String type) {
		List<String> projectIdList = new ArrayList<String>(projectIds);
		return projectDataDownLoadRecordMapper.getIsRunningDownloadFileRecord(projectIdList, type);
	}

	@Override
	public void deleteProjectRecord(String projectId, String updateBy) {
		try {
			projectDataDownLoadRecordMapper.deleteProjectRecord(projectId, LocalDateTime.now(), updateBy);
		}catch (Exception e) {
			log.error("删除项目记录异常，{}", e);
		}
	}
}
